package com.yinuo.health.controller;

import com.alibaba.dubbo.config.annotation.Reference;


import com.yinuo.health.constant.MessageConstant;
import com.yinuo.health.entity.PageResult;
import com.yinuo.health.entity.QueryPageBean;
import com.yinuo.health.entity.Result;

import com.yinuo.health.pojo.CheckItem;
import com.yinuo.health.service.CheckItemService;
import org.springframework.web.bind.annotation.*;

import java.util.List;


@RestController
@RequestMapping("/checkitem")
public class CheckItemController {

    @Reference
    private CheckItemService checkItemService;


    /**
     * 查询所有
     * @return
     */
    @GetMapping("/findAll")
    public Result findAll(){

        List<CheckItem> list = checkItemService.findAll();
        return new Result(true , MessageConstant.QUERY_CHECKITEM_SUCCESS,list);
    }


    /**
     * 添加检查项
     */
    @PostMapping("/add")
    public Result add(@RequestBody CheckItem checkItem){
        checkItemService.add(checkItem);
        return new Result(true , MessageConstant.ADD_CHECKITEM_SUCCESS);
    }

    /**
     * 检查项的分页查询
     */
    @PostMapping("/findPage")
    public Result findPage(@RequestBody QueryPageBean queryPageBean){
        //调用服务查询
        PageResult<CheckItem> pageResult = checkItemService.findPage(queryPageBean);
        return new Result(true , MessageConstant.QUERY_CHECKITEM_SUCCESS,pageResult);
    }


    /**
     * 通过id查询
     */
    @GetMapping("/findById")
    public Result findById(int id){
        CheckItem checkItem = checkItemService.findById(id);
        return new Result(true , MessageConstant.QUERY_CHECKITEM_SUCCESS,checkItem);

    }



    /**
     * 修改检查项
     */
    @PostMapping("/update")
    public Result update(@RequestBody CheckItem checkItem){
        checkItemService.update(checkItem);
        return new Result(true , MessageConstant.EDIT_CHECKITEM_SUCCESS);
    }


    /**
     * 通过id删除
     */
    @PostMapping("/deleteById")
    public Result deleteById(int id){
        checkItemService.deleteById(id);
        return new Result(true , MessageConstant.DELETE_CHECKITEM_SUCCESS);
    }


}
